package com.resource.jwt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author: hw
 * @date: 2020/12/15 11:01
 */
@Component
public class ResourceToken implements ResourceServerTokenServices {

    @Autowired
    private TokenStore tokenStore;

    @Override
    public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException, InvalidTokenException {

        DefaultTokenServices service = new DefaultTokenServices();
        //令牌存储策略
        service.setTokenStore(tokenStore);
        OAuth2Authentication oAuth2Authentication = service.loadAuthentication(accessToken);
        return oAuth2Authentication;
    }

    @Override
    public OAuth2AccessToken readAccessToken(String accessToken) {
        return null;
    }
}
